<template>
  <div>
    <Header></Header>
    <Banner></Banner>
    <div class="main">
      <div class="main-left">
        <li @click="$router.push('/wz')" v-if="this.author == 2">
          <i class="iconfont icon-all-wenzhang"></i>
          我的文章
        </li>
        <li @click="$router.push('/sc')">
          <i class="iconfont icon-all-xiangqu"></i>
          我的关注
        </li>
        <li class="active" @click="$router.push('/wd')">
          <i class="iconfont icon-all-wendabangzhu"></i>
          我的问答
        </li>
        <li @click="$router.push('/pl')">
          <i class="iconfont icon-all-pinglun"></i>
          我的评论
        </li>
        <li @click="$router.push('/dy')">
          <i class="iconfont icon-all-yonghuming"></i>
          我的订阅
        </li>
        <li @click="$router.push('/ds')">
          <i class="iconfont icon-all-qian"></i>
          我的打赏
        </li>
        <li @click="$router.push('/tz')">
          <i class="iconfont icon-all-tongzhi"></i>
          通知中心
        </li>
        <li @click="$router.push('/ll')">
          <i class="iconfont icon-all-liulan"></i>
          浏览记录
        </li>
        <li @click="$router.push('/sz')">
          <i class="iconfont icon-all-icon_setting"></i>
          资料设置
        </li>
      </div>
      <div class="main-right">
        <div class="nav">
          <span @click="ask" v-bind:class="{ active1: isActive1}">我的回答 （{{replyCount}}）</span>
          <span @click="tw" v-bind:class="{ active2: isActive2}">我的提问（{{questionCount}}）</span>
        </div>
        <div class="content" v-if="question">
          <div style="text-align: center; font-size:16px;padding-top:10px;" v-if="this.questionList.length==0">您还没有发布任何问题</div>
          <div class="search" v-if="this.questionList.length>0">
            <i class="iconfont icon-all-sousuo1"></i>
            <input type="text" placeholder="搜索您发布的问答">
          </div>
          <div v-if="this.questionList.length>0"> 
            <div class="content-item" v-for="(item,index) in questionList" :key="index">
              <span class="content-tip" @click="goQuestion(item)">{{item.title}}</span>
              <span>
                <i class="iconfont icon-all-tubiao-" ></i>
                {{item.add_time}}
                <!-- <i
                  class="iconfont icon-all-shanchu"
                  style="color:red; padding-left:10px;cursor: pointer;"
                  @click="cancel(item)"
                ></i> -->
              </span>
            </div>
          </div>
          <div class="more" v-if="questionCount>10">
            <button @click="getMoreQ">加载更多</button>
          </div>
        </div>
        <div class="content" v-if="reply">
          <div style="text-align: center; font-size:16px;padding-top:10px;" v-if="this.questionList.length==0">您还没有任何回复</div>
          <div class="search" v-if="this.questionList.length>0">
            <i class="iconfont icon-all-sousuo1"></i>
            <input type="text" placeholder="搜索您关注的问答">
          </div>
          <div v-if="this.questionList.length>0">
            <div class="content-item" v-for="(item,index) in replyList" :key="index">
              <span class="content-tip" @click="goReply(item)">{{item.content}}</span>
              <span>
                <i class="iconfont icon-all-tubiao-"></i>
                {{item.add_time}}
                <!-- <i
                  class="iconfont icon-all-shanchu"
                  style="color:red; padding-left:10px;cursor: pointer;"
                  @click="cancel(item)"
                ></i> -->
              </span>
            </div>
          </div>
          <div class="more" v-if="replyCount>10">
            <button @click="getMoreR">加载更多</button>
          </div>
        </div>
      </div>
    </div>
    <Footer></Footer>
  </div>
</template>

<script>
import Header from "@/common/Header/Header";
import Footer from "@/common/Footer/Footer";
import Banner from "@/common/Banner/Banner";
export default {
  name: "wd",
  data() {
    return {
      question: false,
      reply: true,
      isActive1: true,
      isActive2: false,
      questionIndex: 10,
      replyIndex: 10,
      questionList: [],
      replyList: [],
      questionCount:'',
      replyCount:'',
      author:"",
    };
  },
  methods: {
    ask() {
      this.question = false;
      this.reply = true;
      this.isActive1 = true;
      this.isActive2 = false;
    },
    tw() {
      this.question = true;
      this.reply = false;
      this.isActive1 = false;
      this.isActive2 = true;
    },
    //获取我的问题
    getAllQuestion() {
      this.$axios
        .get(
          "api/App/User/Set/user_article?member_id=" +
            this.getCookie("member_id") +
            "&p=1&type=1&limit=" +
            this.questionIndex +
            "&to_member_id=" +
            this.getCookie("member_id")
        )
        .then(res => {
          this.questionList = res.data.data.list;
         this.questionCount= res.data.data.count;
        });
    },
    //获取我的回答
    getAllReply() {
       this.$axios
        .get(
          "api/App/User/Set/user_answer?member_id=" +
            this.getCookie("member_id") +
            "&p=1&type=1&limit=" +
            this.replyIndex +
            "&to_member_id=" +
            this.getCookie("member_id")
        )
        .then(res => {
          this.replyList = res.data.data.list;
          this.replyCount= res.data.data.count;
        });
    },
    //点击我发布的问题 跳转到对应的页面
    goQuestion(item){
     console.log(item)
     this.$router.push({
        path: "/replyQuestion",
        query: { questions_id: item.id }
      });
    },
    //点击我发布的问题 跳转到对应的页面
    goReply(item){
      console.log(item)
      this.$router.push({
        path: "/questionList",
        query: { comment_id: item.id }
      });
    },
    //加载更多我的回答
    getMoreR(){
        this.replyIndex = this.replyIndex + 10
      this.$axios
        .get(
          "api/App/User/Set/user_answer?member_id=" +
            this.getCookie("member_id") +
            "&p=1&type=1&limit=" +
            this.replyIndex +
            "&to_member_id=" +
            this.getCookie("member_id")
        )
        .then(res => {
          this.replyList = res.data.data.list;
          this.replyCount= res.data.data.count;
        });
    },
    //加载更多我的提问
    getMoreQ(){
        this.questionIndex = this.questionIndex +10
        this.$axios
        .get(
          "api/App/User/Set/user_article?member_id=" +
            this.getCookie("member_id") +
            "&p=1&type=1&limit=" +
            this.questionIndex +
            "&to_member_id=" +
            this.getCookie("member_id")
        )
        .then(res => {
          this.questionList = res.data.data.list;
         this.questionCount= res.data.data.count;
        });
    }
  },
   mounted () {
       this.author =this.getCookie("identity_type") 
   },
  created() {
    this.getAllQuestion();
    this.getAllReply();
  },
  components: {
    Header,
    Banner,
    Footer
  }
};
</script>
<style lang="scss" scoped>
.main {
  width: 60%;
  height: auto;
  margin: 0 auto;
  margin-top: 30px;
  margin-bottom: 30px;
  display: flex;
  justify-content: space-between;
  .main-left {
    width: 230px;
    background-color: #fff;
    li {
      padding: 20px;
      list-style: none;
      border-left: 1px solid transparent;
      font-size: 18px;
      cursor: pointer;
    }
    .active {
      background-color: #f2f5fb;
      border-left: 1px solid #5079b7;
      color: #5079b7;
    }
  }
  .main-right {
    text-align: left;
    width: 900px;
    background-color: #fff;
    padding: 20px;
    margin-left: 30px;
    .nav {
      line-height: 1.8;
      border-bottom: 1px solid #5079b7;
      span {
        padding-bottom: 8px;
        display: inline-block;
        margin-right: 10px;
        cursor: pointer;
      }
      .money {
        margin-left: 325px;
      }
      .active1 {
        border-bottom: 1px solid #5079b7;
        color: #5079b7;
      }
      .active2 {
        border-bottom: 1px solid #5079b7;
        color: #5079b7;
      }
    }
    .content {
        overflow: auto;
      height: 600px;
      .search {
        padding-left: 5px;
        input {
          border: none;
          outline: none;
          line-height: 30px;
        }
        input::-webkit-input-placeholder {
          color: #666;
          font-size: 12px;
          // padding-left: 10px;
          // letter-spacing: 2px;
        }
        input:-moz-placeholder {
          color: #666;
          font-size: 12px;
          // padding-left: 10px;
          // letter-spacing: 2px;
        }
        input:-ms-input-placeholder {
          color: #666;
          font-size: 12px;
          // padding-left: 10px;
          // letter-spacing: 2px;
        }
      }
      .content-item {
        margin-top: 10px;
        padding-bottom: 10px;
        padding-left: 5px;
        padding-right: 5px;
        display: flex;
        justify-content: space-between;
        border-bottom: 1px solid #999;
        .content-tip{
            display: block;
            width: 70%;
            overflow: hidden;
            text-overflow:ellipsis;
            white-space: nowrap;
            cursor: pointer;
        }
      }
      .more {
        width: 100%;
        text-align: center;
        button {
          border-radius: 10px;
          border: 0;
          outline: none;
          background: linear-gradient(90deg, #00aeff, #3369e7);
          color: #fff;
          box-shadow: 0 2px 6px 0 rgba(51, 105, 231, 0.4);
          margin-top: 20px;
          cursor: pointer;
        }
      }
    }
  }
}
</style>


